<?php
/**
 * 评论公共页面
 * User: lxq
 * Date: 2018/4/20
 * Time: 15:24
 */
class commentControl extends Control{

    public function __construct()
    {
        parent::__construct();
        Tpl::setDir('home');
        Tpl::setLayout('new_layout');
    }

    /**
     * 列表页
     */
    public function indexOp()
    {
        /* @var commentModel $comment_model */
        $comment_model = Model('comment');
        $goods_id = intval($_GET['g_id']);
        $cmt_type = intval($_GET['type_id']);
        $mc_id = intval($_GET['mc_id']);
        $condition = array();
        if($mc_id>0){
            $condition['merchant_id'] =$mc_id;
        }else{
            $condition['goods_id'] = $goods_id;
        }
        $condition['cmt_type'] = $cmt_type;
        $comment_list = $comment_model->getCommentPage($condition,'',10);
        if($comment_list && is_array($comment_list)){
            foreach($comment_list as $key => $value){
                //评论图片
                if($value['pic_1']){
                    $comment_list[$key]['pic_1'] = UPLOAD.'comment/'.$value['pic_1'];
                }
                if($value['pic_2']){
                    $comment_list[$key]['pic_2'] = UPLOAD.'comment/'.$value['pic_2'];
                }
                if($value['pic_3']){
                    $comment_list[$key]['pic_3'] = UPLOAD.'comment/'.$value['pic_3'];
                }
                $comment_list[$key]['member_name'] = nickname_hide($value['member_name']);
            }
        }
        Tpl::output('comment_list',$comment_list);
        //AJAX加载分页
        if(isset($_GET['isajax']) && $_GET['isajax'] == 1){
            Tpl::showpage('comment.index.page','null_layout');
            exit;
        }
        Tpl::output('TotalNum',pagecmd("gettotalnum"));
        Tpl::output('TotalPage',pagecmd("gettotalpage"));
        Tpl::showpage('comment.index');
    }
}